I = lambda: list(map(int, input().split()))
for _ in range(int(input())):
n=int(input())
a=I()
y=max(a)
x=a.index(y)
if x==0 or x==n-1:
a.remove(y)
a.reverse()
print(*(a+[y]))
else:
print(-1)
//In the name of Almighty Allah
#include<bits/stdc++.h>
using namespace std;
#define mod 1e9+7
#define fast ios_base::sync_with_stdio(false), cin.tie(nullptr), cout.tie(nullptr);
#define case(z) cout<<"Case "<<z<<": "
#define ll long long
#define nl "\n"
#define NO cout << "NO" << endl;
#define Yes cout << "Yes" << endl;
#define No cout << "No" << endl;
#define yes cout << "yes" << endl;
#define no cout << "no" << endl;
#define YES cout << "YES" << endl;
ll gcd(ll a,ll b){
return __gcd(a,b);
}
ll lcm(ll a,ll b){
return (a*(b/gcd(a,b)));
}
const int mx=2e5+123;
int a[mx];
int main()
{
fast;
int t,i,j,x,g,type,n,k,diff,m;
cin>>t;
while(t--)
{
cin>>n;
for(i=1;i<=n;i++)
cin>>a[i];
m=*max_element(a+1,a+n+1);
if(a[1]!=m and a[n]!=m)
{
cout<<-1<<nl;
continue;
}
cout<<a[1]<<' ';
for(i=n;i>1;i--)
cout<<a[i]<<' ';
cout<<nl;
}
return 0;
}
189A - Cut Ribbon | 1182A - Filling Shapes |
82A - Double Cola | 45A - Codecraft III |
1242A - Tile Painting | 1663E - Are You Safe |
1663D - Is it rated - 3 | 1311A - Add Odd or Subtract Even |
977F - Consecutive Subsequence | 939A - Love Triangle |
755A - PolandBall and Hypothesis | 760B - Frodo and pillows |
1006A - Adjacent Replacements | 1195C - Basketball Exercise |
1206A - Choose Two Numbers | 1438B - Valerii Against Everyone |
822A - I'm bored with life | 9A - Die Roll |
1430B - Barrels | 279B - Books |
1374B - Multiply by 2 divide by 6 | 1093B - Letters Rearranging |
1213C - Book Reading | 1468C - Berpizza |
1546B - AquaMoon and Stolen String | 1353C - Board Moves |
902A - Visiting a Friend | 299B - Ksusha the Squirrel |
1647D - Madoka and the Best School in Russia | 1208A - XORinacci |